home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / Relative Time Strings / About Relative Time Strings next >
Encoding:
Text File  |  1994-11-08  |  5.8 KB  |  86 lines  |  [TEXT/ttxt]

  1.     File:              Relative Time Strings.c
  2.     Written by:        Chris Hufford  CIS: 70076,1707
  3.                        Geoff Hufford  CIS: 72627,3511
  4.     
  5.     Description:    
  6.         These routines were written for and used in our Shareware program called
  7.         Eye On The Clock. These routines will take two dates and times and create a
  8.         string, in MANY different formats, of how much time there is between the two
  9.         dates and times. Basically you need to load up the Count_Rec structure and call
  10.         Get_Rel_Time_Str and your done.
  11.         
  12.         These routines reference 'STR#' resource 129 for all text used to build the string
  13.         
  14.         There are many supporting routines for both time/date stuff as well as strings
  15.         which may be useful on their own.
  16.     
  17.     Here is an example of loading up the Count_Rec:
  18.     
  19.         Count_Rec        time_rec;
  20.         Str255            the_str;
  21.     
  22.     time_rec.Display.fractional        = FALSE;
  23.     time_rec.Display.significant     = FALSE;
  24.     time_rec.Display.count_days     = FALSE;
  25.     time_rec.Display.hide_zeros     = FALSE;
  26.     time_rec.Display.allow_clock_display = FALSE;
  27.     time_rec.Display.allow_day_rounding  = FALSE;
  28.     time_rec.Display.abbreviated     = FALSE;
  29.  
  30.     time_rec.Target_In_Secs = 2840227200;            // target time to display (in seconds) 1/1/90
  31.     time_rec.From_In_Secs   = 3000000000;            // from time to display (in seconds)
  32.  
  33.     // you may add only the items which you want displayed:
  34.     time_rec.Display.display_items = year + month + week + day + hour + minute + second;
  35.     
  36.     Get_Rel_Time_Str (&time_rec, the_str);
  37.     // then display or use the_str)
  38.  
  39. The following are excerpts from the Eye On The Clock about file which should further describe the many display options that these routines have:
  40.  
  41.  
  42. Eye On The Clock will display continuously updating time counters for important times and dates you configure. It will show the length of time until or since each event in a variety of user selectable formats. There can be events which reoccur at selectable intervals. Events might include:
  43.  
  44. • Keeping track of exactly how many days until a project is due
  45. • Number of weeks until special holidays or events like birthdays and anniversaries
  46. • Number of seconds until the weekend
  47. • How many months old your baby is
  48. • Number of days until vacation
  49.  
  50. Display Options:
  51. --------------
  52. Below the date and time boxes are a series of checkbox display options. There you can select which divisions of time you would like to see for the selected event.
  53.  
  54. For example, if the event is many years away, you may only wish to see how many years and months until the event. So check "Years" and "Months" and un-check "Weeks", "Days", "Hours", "Minutes" and "Seconds". Below the checkboxes is an example of how the display will look. As you change checkbox options, the example will change to reflect your selections.
  55.  
  56. Months are a special display type because of their varying lengths.
  57. For example- if the current date 1/31/94 and the event date is set to 3/2/94, a result of "1-month 2-days" will be displayed.  The computer tries to move forward 1 month but realizes that no 2/31/94 exists so it counts 1 month from 1/31 to be the last day of February (2/28/94) and then counts the days from there to the event.  Notice that this can create some interesting results.  A current date of 1/28 through 1/31 and the same event date of 3/2 will all yield the same result of 1-month 2-days.  When the current date changes to 2/1, the display will change to 1-month 1-day.
  58.  
  59. Fractional checkbox:
  60. The fractional checkbox will display the smallest checked time unit as a decimal number. Rather than an event being 1 month away, it will be displayed as 1.432 months away.
  61.  
  62. Only Display Largest Time Unit:
  63. This checkbox lets you select many divisions of time, but will only display the largest applicable division. For example, if an event is 1 month away, and you have selected only weeks, days and minutes, then Eye On The Clock will just display the number of weeks until the event is less than a week away. Then the display will change to the next selected display type, days, until the event is less than a day away. Then the display will countdown the minutes until the event.
  64.  
  65. This is useful if you don't need a precise display, until the event is imminent.
  66.  
  67. Count Days since event:
  68. For events in the past, this option counts the days. The day of the event is considered "Day #1" rather than '0 days since'. This will supersede all of the other display options (no hours, minutes, seconds etc.).
  69.  
  70. This setting will have no effect on events that are still in the future.
  71.  
  72. Hide Zeros:
  73. This option controls whether or not Eye On The Clock will display time divisions which are zero. When Hide Zeros in on, even if you have years selected as a display option, you will not see any year value if the event is less than a year away. 
  74.  
  75. Allow Clock display:
  76. Selecting this option allows Eye On The Clock to display hours, minutes and seconds in a clock format (3-days 4:34:54). Not selecting this option displays each time division separately (3-days 4-hours 34-minutes 54-seconds).
  77.  
  78. Change Days at Midnight:
  79. This option controls how days are counted if Hours, Minutes and Seconds are not selected as display options.  Selecting this option causes the day count to change at midnight. This is probably the way you would count days if you looked at a calendar. Not selecting this option causes the day count to change at the event time.
  80. For example, with "Change Days at Midnight" selected, an event whose time is 1:00 am would display '1-day until' until midnight of the day before the event. When "Change Days at Midnight" is not selected, the same event would display '0-days until' starting at 1:00 am of the previous day.
  81.  
  82. Limitations:
  83. -----------
  84. Eye On The Clock uses the Mac clock to store and compute times and dates. Because of the way that the Mac deals with time, Eye On The Clock can only support dates from 1/1/1904 through 2/6/2040. Event dates not within this range will produce incorrect calculations.
  85.  
  86.